/* Gyroe 1.0.0 */
/* scanner.c : Handles all lexical analysis. Also handles
   all includes besides the first one, as well as storing
   data for each file (called trace, profile or not, etc.).
   Lastly, handles setting up the stack for trace. */

#include "euphoria.h"
#include "main-.h"
#include "sym_fields.h"

int _11InitLex()
{
    int i;
    object_ptr Base;
    s1_ptr ptr;

    _4gline_number = 0;
    _4line_number = 0;

    RefDS(_39);
    DeRef(_11IncludeStk);
    _11IncludeStk = _39;

    // char_class = repeat(ILLEGAL_CHAR, 255)  -- we screen out the 0 character
    DeRefi(_11char_class);
    _11char_class = Repeat(-20, 255);

    ptr = SEQ_PTR(_11char_class);
    Base = ptr->base;

    for (i = 48;i < 58;i++) {
        Base[i] = -7; /* '0' to '9' : DIGIT */
    }
    for (i = 65;i < 91;i++) {
        Base[i] = -2; /* 'A' to 'Z' : LETTER */
    }
    for (i = 97;i < 123;i++) {
        Base[i] = -2; /* 'a' to 'z' : LETTER*/
    }

    // char_class['\t'] = BLANK
    Base[9] = -8;

    // char_class['\n'] = NEWLINE
    Base[10] = -6;

    // char_class['\r'] = NEWLINE
    Base[13] = -6;

    // char_class[END_OF_FILE_CHAR] = END_OF_FILE
    Base[26] = -21;

    // char_class[' '] = BLANK
    Base[32] = -8;

    // char_class['!'] = BANG
    Base[33] = -1;

    // char_class['"'] = DOUBLE_QUOTE
    Base[34] = -4;

    // char_class['#'] = NUMBER_SIGN
    Base[35] = -11;

    // char_class['$'] = DOLLAR
    Base[36] = -22;

    // char_class['&'] = CONCAT
    Base[38] = 15;

    // char_class['\''] = SINGLE_QUOTE
    Base[39] = -5;

    // char_class['('] = LEFT_ROUND
    Base[40] = -26;

    // char_class[')'] = RIGHT_ROUND
    Base[41] = -27;

    // char_class['*'] = MULTIPLY
    Base[42] = 13;

    // char_class['+'] = PLUS
    Base[43] = 11;

    // char_class[','] = COMMA
    Base[44] = -30;

    // char_class['-'] = MINUS
    Base[45] = 10;

    // char_class['.'] = DOT
    Base[46] = -3;

    // char_class['/'] = DIVIDE
    Base[47] = 14;

    // char_class[':'] = COLON
    Base[58] = -23;

    // char_class['<'] = LESS
    Base[60] = 1;

    // char_class['='] = EQUALS
    Base[61] = 3;

    // char_class['>'] = GREATER
    Base[62] = 6;

    // char_class['?'] = QUESTION_MARK
    Base[63] = -31;

    // char_class['['] = LEFT_SQUARE
    Base[91] = -28;

    // char_class[']'] = RIGHT_SQUARE
    Base[93] = -29;

    // char_class['{'] = LEFT_BRACE
    Base[123] = -24;

    // char_class['}'] = RIGHT_BRACE
    Base[125] = -25;

    // id_char = repeat(FALSE, 255)
    DeRefi(_11id_char);
    _11id_char = Repeat(0, 255);

    ptr = SEQ_PTR(_11id_char);
    Base = ptr->base;

    /* id_char is used to determine if we have
       a character than can be used to 'id' a
       routine or a variable. */

    for (i = 48;i < 58;i++) {
        Base[i] = 1; /* '0' to '9' : TRUE*/
    }
    for (i = 65;i < 91;i++) {
        Base[i] = 1; /* 'A' to 'Z' : TRUE */
    }
    for (i = 97;i < 123;i++) {
        Base[i] = 1; /* 'a' to 'z' : TRUE */
    }

    Base[95] = 1; // '_'
}

int _11ResetTP()
/* Set all 'with' options to off. */
{
    _4OpTrace = 0;
    _4OpProfileStatement = 0;
    _4OpProfileTime = 0;
    _11AnyStatementProfile = 0;
    _11AnyTimeProfile = 0;
}

int _11pack_source(int src)
{
    int start;
    int _1550 = 0;
    int _1, _2;

    //     if equal(src, 0) then
    if (src == 0)
        _1550 = 1;
    else if (IS_ATOM_INT(src) && IS_ATOM_INT(0))
        _1550 = 0;
    else
        _1550 = (compare(src, 0) == 0);
    if (_1550 == 0)
        goto L1;

    // 	return 0
    DeRefi(src);
    return 0;
L1:

    //     if length(src) >= SOURCE_CHUNK then
    DeRef(_1550);
    _1550 = SEQ_PTR(src)->length;
    if (_1550 < 10000)
        goto L2;

    // 	src = src[1..80] -- enough for trace or profile display
    rhs_slice_target = (object_ptr)&src;
    RHS_Slice((s1_ptr)src, 1, 80);
L2:

    //     if current_source_next + length(src) >= SOURCE_CHUNK then
    DeRef(_1550);
    _1550 = SEQ_PTR(src)->length;
    _1550 = _11current_source_next + _1550;
    if (_1550 + HIGH_BITS >= 0)
        _1550 = NewDouble((double)_1550);
    if (binary_op_a(LESS, _1550, 10000))
        goto L3;

    // 	current_source = allocate(SOURCE_CHUNK)
    DeRef(_11current_source);
    _11current_source = _7allocate(10000);

    // 	if current_source = 0 then
    if (binary_op_a(NOTEQ, _11current_source, 0))
        goto L4;

    // 	    CompileErr("out of memory - turn off trace and profile")
    RefDS(_1559);
    _6CompileErr(_1559);
L4:

    // 	all_source = append(all_source, current_source)
    Ref(_11current_source);
    Append(&_11all_source, _11all_source, _11current_source);

    // 	current_source_next = 1
    _11current_source_next = 1;
L3:

    //     start = current_source_next
    start = _11current_source_next;

    //     poke(current_source+current_source_next, src)
    DeRef(_1550);
    if (IS_ATOM_INT(_11current_source)) {
        _1550 = _11current_source + _11current_source_next;
        if (_1550 + HIGH_BITS >= 0)
            _1550 = NewDouble((double)_1550);
    }
    else {
        _1550 = NewDouble(DBL_PTR(_11current_source)->dbl + (double)_11current_source_next);
    }
    if (IS_ATOM_INT(_1550))
        poke_addr = (unsigned char *)_1550;
    else
        poke_addr = (unsigned char *)(unsigned long)(DBL_PTR(_1550)->dbl);
    if (IS_ATOM_INT(src)) {
        *poke_addr = (unsigned char)src;
    }
    else if (IS_ATOM(src)) {
        *poke_addr = (signed char)DBL_PTR(src)->dbl;
    }
    else {
        _1 = (int)SEQ_PTR(src);
        _1 = (int)((s1_ptr)_1)->base;
        while (1) {
            _1 += 4;
            _2 = *((int *)_1);
            if (IS_ATOM_INT(_2))
                *poke_addr++ = (unsigned char)_2;
            else if (_2 == NOVALUE)
                break;
            else {
                *poke_addr++ = (signed char)DBL_PTR(_2)->dbl;
            }
        }
    }

    //     current_source_next += length(src)-1
    DeRef(_1550);
    _1550 = SEQ_PTR(src)->length;
    _1550 = _1550 - 1;
    _11current_source_next = _11current_source_next + _1550;

    //     poke(current_source+current_source_next, 0) -- overwrite \n
    if (IS_ATOM_INT(_11current_source)) {
        _1550 = _11current_source + _11current_source_next;
        if (_1550 + HIGH_BITS >= 0)
            _1550 = NewDouble((double)_1550);
    }
    else {
        _1550 = NewDouble(DBL_PTR(_11current_source)->dbl + (double)_11current_source_next);
    }
    if (IS_ATOM_INT(_1550))
        poke_addr = (unsigned char *)_1550;
    else
        poke_addr = (unsigned char *)(unsigned long)(DBL_PTR(_1550)->dbl);
    *poke_addr = (unsigned char)0;

    //     current_source_next += 1
    _11current_source_next = _11current_source_next + 1;

    //     return start + SOURCE_CHUNK * (length(all_source)-1)
    DeRef(_1550);
    _1550 = SEQ_PTR(_11all_source)->length;
    _1550 = _1550 - 1;
    if (_1550 <= INT15)
        _1550 = 10000 * _1550;
    else
        _1550 = NewDouble(10000 * (double)_1550);
    if (IS_ATOM_INT(_1550)) {
        _1550 = start + _1550;
        if (_1550 + HIGH_BITS >= 0)
            _1550 = NewDouble((double)_1550);
    }
    else {
        _1550 = NewDouble((double)start + DBL_PTR(_1550)->dbl);
    }
    DeRefi(src);
    return _1550;
    ;
}

int _11AppendSourceLine()
{
    int new = 0, old = 0, options = 0, src = 0;
    int _1581 = 0, _1598 = 0, _1603 = 0;
    int _1, _2;

    //     src = 0
    /* src = 0 */

    //     options = 0
    /* options = 0 */

    //     if TRANSLATE or OpTrace or OpProfileStatement or OpProfileTime then
    if (0 != 0) {
        _1581 = 1;
        goto L1;
    }
    _1581 = (_4OpTrace != 0);
L1:
    if (_1581 != 0) {
        DeRef(_1581);
        _1581 = 1;
        goto L2;
    }
    _1581 = (_4OpProfileStatement != 0);
L2:
    if (_1581 != 0) {
        goto L3;
    }
L4:
    if (_4OpProfileTime == 0)
        goto L5;
L3:

    // 	src = ThisLine
    Ref(_6ThisLine);
    DeRefi(src);
    src = _6ThisLine;

    // 	if ELINUX and TRANSLATE and mybsd then
    if (_4ELINUX == 0) {
        DeRef(_1581);
        _1581 = 0;
        goto L6;
    }
    _1581 = (0 != 0);
L6:
    if (_1581 == 0) {
        goto L7;
    }
L8:
    if (_4mybsd == 0)
        goto L7;

    // 	    src = ""  -- save space, only 8Mb available!
    RefDS(_39);
    DeRefi(src);
    src = _39;
L7:

    // 	if OpTrace then
    if (_4OpTrace == 0)
        goto L9;

    // 	    options = SOP_TRACE
    options = 1;
L9:

    // 	if OpProfileTime then
    if (_4OpProfileTime == 0)
        goto LA;

    // 	    options = or_bits(options, SOP_PROFILE_TIME)
    options = (options | 2);
LA:

    // 	if OpProfileStatement then
    if (_4OpProfileStatement == 0)
        goto LB;

    // 	    options = or_bits(options, SOP_PROFILE_STATEMENT)
    options = (options | 4);
LB:

    // 	if OpProfileStatement or OpProfileTime then
    if (_4OpProfileStatement != 0) {
        goto LC;
    }
LD:
    if (_4OpProfileTime == 0)
        goto LE;
LC:

    // 	    src = {0,0,0,0} & src
    _1 = NewS1(4);
    _2 = (int)((s1_ptr)_1)->base;
    *((int *)(_2+4)) = 0;
    *((int *)(_2+8)) = 0;
    *((int *)(_2+12)) = 0;
    *((int *)(_2+16)) = 0;
    _1581 = MAKE_SEQ(_1);
    if (IS_SEQUENCE(_1581) && IS_ATOM(src)) {
        Ref(src);
        Append(&src, _1581, src);
    }
    else if (IS_ATOM(_1581) && IS_SEQUENCE(src)) {
    }
    else {
        Concat((object_ptr)&src, _1581, (s1_ptr)src);
    }
LE:
L5:
    //     if length(slist) then
    DeRef(_1581);
    _1581 = SEQ_PTR(_4slist)->length;
    if (_1581 == 0)
        goto LF;

    // 	old = slist[$-1]
    _1581 = SEQ_PTR(_4slist)->length;
    _1581 = _1581 - 1;
    DeRef(old);
    _2 = (int)SEQ_PTR(_4slist);
    old = (int)*(((s1_ptr)_2)->base + _1581);
    Ref(old);

    // 	if equal(src, old[SRC]) and
    _2 = (int)SEQ_PTR(old);
    _1581 = (int)*(((s1_ptr)_2)->base + 1);
    Ref(_1581);
    if (src == _1581)
        _1581 = 1;
    else if (IS_ATOM_INT(src) && IS_ATOM_INT(_1581))
        _1581 = 0;
    else
        _1581 = (compare(src, _1581) == 0);
    if (_1581 == 0) {
        _1581 = 0;
        goto L10;
    }
    DeRef(_1598);
    _2 = (int)SEQ_PTR(old);
    _1598 = (int)*(((s1_ptr)_2)->base + 3);
    Ref(_1598);
    if (IS_ATOM_INT(_1598)) {
        _1598 = (_4current_file_no == _1598);
    }
    else {
        _1598 = binary_op(EQUALS, _4current_file_no, _1598);
    }
    if (IS_ATOM_INT(_1598))
        _1581 = (_1598 != 0);
    else
        _1581 = DBL_PTR(_1598)->dbl != 0.0;
L10:
    if (_1581 == 0) {
        DeRef(_1598);
        _1598 = 0;
        goto L11;
    }
    DeRef(_1581);
    _2 = (int)SEQ_PTR(old);
    _1581 = (int)*(((s1_ptr)_2)->base + 2);
    Ref(_1581);
    if (IS_ATOM_INT(_1581)) {
        _1581 = _1581 + 1;
        if (_1581 > MAXINT)
            _1581 = NewDouble((double)_1581);
    }
    else
        _1581 = binary_op(PLUS, 1, _1581);
    DeRef(_1603);
    _1603 = SEQ_PTR(_4slist)->length;
    _2 = (int)SEQ_PTR(_4slist);
    _1603 = (int)*(((s1_ptr)_2)->base + _1603);
    Ref(_1603);
    if (IS_ATOM_INT(_1581) && IS_ATOM_INT(_1603)) {
        _1603 = _1581 + _1603;
        if (_1603 + HIGH_BITS >= 0)
            _1603 = NewDouble((double)_1603);
    }
    else {
        _1603 = binary_op(PLUS, _1581, _1603);
    }
    if (IS_ATOM_INT(_1603)) {
        _1603 = (_4line_number == _1603);
    }
    else {
        _1603 = binary_op(EQUALS, _4line_number, _1603);
    }
    if (IS_ATOM_INT(_1603))
        _1598 = (_1603 != 0);
    else
        _1598 = DBL_PTR(_1603)->dbl != 0.0;
L11:
    if (_1598 == 0) {
        goto L12;
    }
    DeRef(_1581);
    _2 = (int)SEQ_PTR(old);
    _1581 = (int)*(((s1_ptr)_2)->base + 4);
    Ref(_1581);
    if (IS_ATOM_INT(_1581)) {
        _1581 = (options == _1581);
    }
    else {
        _1581 = binary_op(EQUALS, options, _1581);
    }
L13:
    if (_1581 == 0) {
        goto L12;
    }
    else {
        if (!IS_ATOM_INT(_1581) && DBL_PTR(_1581)->dbl == 0.0)
            goto L12;
    }

    // 	    slist[$] += 1
    DeRef(_1581);
    _1581 = SEQ_PTR(_4slist)->length;
    DeRef(_1603);
    _2 = (int)SEQ_PTR(_4slist);
    _1603 = (int)*(((s1_ptr)_2)->base + _1581);
    Ref(_1603);
    if (IS_ATOM_INT(_1603)) {
        _1603 = _1603 + 1;
        if (_1603 > MAXINT)
            _1603 = NewDouble((double)_1603);
    }
    else
        _1603 = binary_op(PLUS, 1, _1603);
    Ref(_1603);
    _2 = (int)SEQ_PTR(_4slist);
    if (!UNIQUE(_2)) {
        _2 = (int)SequenceCopy((s1_ptr)_2);
        _4slist = MAKE_SEQ(_2);
    }
    _2 = (int)(((s1_ptr)_2)->base + _1581);
    _1 = *(int *)_2;
    *(int *)_2 = _1603;
    DeRef(_1);
    goto L14;
L12:

    // 	    src = pack_source(src)
    Ref(src);
    src = _11pack_source(src);

    // 	    new = {src, line_number, current_file_no, options}
    _1 = NewS1(4);
    _2 = (int)((s1_ptr)_1)->base;
    Ref(src);
    *((int *)(_2+4)) = src;
    *((int *)(_2+8)) = _4line_number;
    *((int *)(_2+12)) = _4current_file_no;
    *((int *)(_2+16)) = options;
    new = MAKE_SEQ(_1);

    // 	    if slist[$] = 0 then
    DeRef(_1603);
    _1603 = SEQ_PTR(_4slist)->length;
    _2 = (int)SEQ_PTR(_4slist);
    _1603 = (int)*(((s1_ptr)_2)->base + _1603);
    Ref(_1603);
    if (binary_op_a(NOTEQ, _1603, 0))
        goto L15;

    // 		slist[$] = new
    DeRef(_1603);
    _1603 = SEQ_PTR(_4slist)->length;
    RefDS(new);
    _2 = (int)SEQ_PTR(_4slist);
    if (!UNIQUE(_2)) {
        _2 = (int)SequenceCopy((s1_ptr)_2);
        _4slist = MAKE_SEQ(_2);
    }
    _2 = (int)(((s1_ptr)_2)->base + _1603);
    *(int *)_2 = new;
    goto L16;
L15:

    // 		slist = append(slist, new)
    RefDS(new);
    Append(&_4slist, _4slist, new);
L16:

    // 	    slist = append(slist, 0)
    Append(&_4slist, _4slist, 0);
L17:
    goto L14;
LF:

    // 	src = pack_source(src)
    Ref(src);
    src = _11pack_source(src);

    // 	slist = {{src, line_number, current_file_no, options}, 0}
    _1 = NewS1(4);
    _2 = (int)((s1_ptr)_1)->base;
    Ref(src);
    *((int *)(_2+4)) = src;
    *((int *)(_2+8)) = _4line_number;
    *((int *)(_2+12)) = _4current_file_no;
    *((int *)(_2+16)) = options;
    _1603 = MAKE_SEQ(_1);
    DeRef(_4slist);
    _1 = NewS1(2);
    _2 = (int)((s1_ptr)_1)->base;
    ((int *)_2)[1] = _1603;
    RefDS(_1603);
    ((int *)_2)[2] = 0;
    _4slist = MAKE_SEQ(_1);
L14:

    // end procedure
    DeRef(new);
    DeRef(old);
    DeRefi(src);
    DeRef(_1603);
    DeRef(_1581);
    DeRef(_1598);
    return 0;
    ;
}

int _11read_line()
{
    int n;
    int _1638;
    int _1, _2;

    //     line_number += 1
    _4line_number = _4line_number + 1;

    //     gline_number += 1
    _4gline_number = _4gline_number + 1;

    //     ThisLine = gets(src_file)
    DeRefi(_6ThisLine);
    _6ThisLine = EGets(_11src_file);

    //     if atom(ThisLine) then
    _1638 = IS_ATOM(_6ThisLine);
    if (_1638 == 0)
        goto L1;

    // 	ThisLine = {END_OF_FILE_CHAR}
    RefDS(_1642);
    DeRefi(_6ThisLine);
    _6ThisLine = _1642;
L1:

    //     bp = 1
    _6bp = 1;

    //     n = length(ThisLine)
    n = SEQ_PTR(_6ThisLine)->length;

    //     if ThisLine[n] != '\n' then
    _2 = (int)SEQ_PTR(_6ThisLine);
    _1638 = (int)*(((s1_ptr)_2)->base + n);
    if (_1638 == 10)
        goto L2;

    // 	ThisLine = append(ThisLine, '\n') -- add missing \n (might happen at end of file)
    Append(&_6ThisLine, _6ThisLine, 10);
L2:

    //     AppendSourceLine()
    _11AppendSourceLine();

    // end procedure
    return 0;
    ;
}

int _11bad_zero()
{
    // CompileErr("illegal character (ASCII 0)")
    RefDS(_1647);
    _6CompileErr(_1647);
}

int _11getch()
{
    int c, _2;

    _2 = (int)SEQ_PTR(_6ThisLine);
    c = (int)*(((s1_ptr)_2)->base + _6bp);

    _6bp++;

    return c;
}

int _11ungetch()
{
    _6bp--;
}

int _11get_file_path(int s)
{
    int i, targ = 0;
    s1_ptr ptr;

    ptr = SEQ_PTR(s);

    for (i = ptr->length;i > 1;i--){
        if (find(ptr->base[i], _4SLASH_CHARS)) {
            rhs_slice_target = (object_ptr)&targ;
            RHS_Slice((s1_ptr)s, 1, i);
            DeRefDS(s);
            return targ;
        }
    }

    // 	return "." & SLASH
    Append(&targ, _1511, _4SLASH);
    DeRefDS(s);
    return targ;
}

int _11path_open()
{
    int absolute, currdir = 0, errbuff = 0, full_path = 0, inc_path = 0;
    int try97531;
    int _1657 = 0, _1660 = 0, _1691 = 0;
    int _1659;
    int _1, _2;
    object_ptr Base;
    s1_ptr ptr;

    /* Is it an absolute path? */
    // absolute = find(new_include_name[1], SLASH_CHARS) or
    ptr = SEQ_PTR(_11new_include_name);

    _2 = (int)SEQ_PTR(_11new_include_name);
    _1657 = (int)*(((s1_ptr)_2)->base + 1);
    Ref(_1657);
    _1657 = find(_1657, _4SLASH_CHARS);
    _1659 = (_4ELINUX == 0);
    _1660 = find(58, _11new_include_name);
    _1660 = (_1659 != 0 && _1660 != 0);
    absolute = (_1657 != 0 || _1660 != 0);

    /* First, try absolute path. */
    if (absolute) {
        // try = open(new_include_name, "r")
        try97531 = EOpen(_11new_include_name, _1663);

        if (try97531 == -1) {
            /* can't open %s */
            err_add(NewString("can't open "));
            err_add(_11new_include_name);
            set_err_stack();
        }

        // return try
        DeRef(full_path);
        DeRefi(inc_path);
        DeRefi(errbuff);
        DeRef(currdir);
        DeRef(_1657);
        DeRef(_1660);
        DeRef(_1691);
        return try97531;
    }

    /* 2nd attempt : Relative from current path
       (Suggested by c.k. lester) */

    DeRef(_1660);
    _2 = (int)SEQ_PTR(_4file_name);
    _1660 = (int)*(((s1_ptr)_2)->base + _4current_file_no);
    RefDS(_1660);
    RefDS(_1660);
    currdir = _11get_file_path(_1660);

    Concat((object_ptr)&full_path, currdir, (s1_ptr)_11new_include_name);

    // try = open(full_path, "r")
    try97531 = EOpen(full_path, _1663);

    if (try97531 == -1) {
        Concat((object_ptr)&full_path, _11main_path, (s1_ptr)_11new_include_name);

        // try = open(full_path,  "r")
        try97531 = EOpen(full_path, _1663);
    }

    /* Try the path from EUINC. */
    if (try97531 == -1) {
        // inc_path = getenv("EUINC")
        DeRefi(inc_path);
        inc_path = EGetEnv(_1676);

        if (IS_SEQUENCE(inc_path) && SEQ_PTR(inc_path)->length > 0) {
            Append(&inc_path, inc_path, _4PATH_SEPARATOR);

            RefDS(_39);
            DeRef(full_path);
            full_path = _39;

            ptr = SEQ_PTR(inc_path);
            Base = ptr->base;

            int len, p;
            len = ptr->length + 1;

            for (p = 1;p < len;p++) {
                ptr = SEQ_PTR(inc_path);
                Base = ptr->base;
                if (*(Base + p) != _4PATH_SEPARATOR) {
                    int finder;
                    Concat((object_ptr)&_1691, _1690, (s1_ptr)_4SLASH_CHARS);

                    while (1) {
                        if (ptr->length == 0)
                            break;
                        ptr = SEQ_PTR(full_path);
                        Base = ptr->base + ptr->length;
                        if (find(*Base, _1691) == 0)
                            break;

                        rhs_slice_target = (object_ptr)&full_path;
                        RHS_Slice((s1_ptr)full_path, 1, SEQ_PTR(full_path)->length - 1);
                    }

                    if (SEQ_PTR(full_path)->length) {
                        {
                            int concat_list[3];

                            concat_list[0] = _11new_include_name;
                            concat_list[1] = _4SLASH;
                            concat_list[2] = full_path;
                            Concat_N((object_ptr)&full_path, concat_list, 3);
                        }

                        // try = open(full_path, "r")
                        try97531 = EOpen(full_path, _1663);

                        if (try97531 == -1)
                            break;

                        RefDS(_39);
                        DeRef(full_path);
                        full_path = _39;
                    }
                }
                else {
                    ptr = SEQ_PTR(inc_path);
                    Base = ptr->base + p;
                    if (SEQ_PTR(full_path)->length || *Base != 32 && *Base != 9) { // ! ' ' && ! '\t'
                        DeRef(_1660);
                        _2 = (int)SEQ_PTR(inc_path);
                        _1660 = (int)*(((s1_ptr)_2)->base + p);
                        Append(&full_path, full_path, _1660);
                    }
                }
            }
            rhs_slice_target = (object_ptr)&inc_path;
            RHS_Slice((s1_ptr)inc_path, 1, SEQ_PTR(inc_path)->length - 1);
        }
    }

    if (try97531 == -1) {
        // full_path = eudir & SLASH & "include" & SLASH & new_include_name
        {
            int concat_list[5];

            concat_list[0] = _11new_include_name;
            concat_list[1] = _4SLASH;
            concat_list[2] = _698;
            concat_list[3] = _4SLASH;
            concat_list[4] = _4eudir;
            Concat_N((object_ptr)&full_path, concat_list, 5);
        }

        // try = open(full_path, "r")
        try97531 = EOpen(full_path, _1663);
    }

    if (try97531 != -1) {
        RefDS(full_path);
        DeRef(_11new_include_name);
        _11new_include_name = full_path;

        // return try
        DeRefDS(full_path);
        DeRefi(inc_path);
        DeRefi(errbuff);
        DeRef(currdir);
        DeRef(_1660);
        DeRef(_1657);
        DeRef(_1691);
        return try97531;
    }

    /* If main path is empty, set to '.'. If not,
       remove (possible) end slash character. */
    if (SEQ_PTR(_11main_path)->length == 0) {
        RefDS(_1511);
        DeRefDS(_11main_path);
        _11main_path = _1511; // "."
    }
    else {
        ptr = SEQ_PTR(_11main_path);
        Base = ptr->base + ptr->length;

        if (find(*Base, _4SLASH_CHARS)) {
            // main_path = main_path[1..$-1]  -- looks better
            rhs_slice_target = (object_ptr)&_11main_path;
            RHS_Slice((s1_ptr)_11main_path, 1, SEQ_PTR(_11main_path)->length - 1);
        }
    }

    Ref(_11main_path);

    if (IS_ATOM(inc_path)) {
        /* can't find %s in %s\nor in %s%sinclude */
        err_add(NewString("can't find "));
        err_add(_11new_include_name);
        err_add(NewString(" in "));
        err_add(_11main_path);
        err_add(NewString("\nor in "));
        err_add(_4eudir);
        err_add(_4SLASH);
        err_add(NewString("include"));
    }
    else {
        /* can't find %s in %s\nor in %s\nor in %s%sinclude */
        err_add(NewString("can't find "));
        err_add(_11new_include_name);
        err_add(NewString(" in "));
        err_add(_11main_path);
        err_add(NewString("\nor in "));
        err_add(inc_path);
        err_add(NewString("\nor in "));
        err_add(_4eudir);
        err_add(_4SLASH);
        err_add(NewString("include"));
    }

    set_err_stack();
}

int _11NameSpace_declaration(int sym)
{
    int h;
    int _2125 = 0, _2133 = 0;
    int _1, _2, _3;
    object_ptr Base;
    s1_ptr ptr;

    _10DefinedYet(sym);

    // if find(SymTab[sym][S_SCOPE], {SC_GLOBAL, SC_PREDEF}) then
    ptr = SEQ_PTR(_4SymTab);
    Base = ptr->base + sym;
    ptr = SEQ_PTR(*Base);
    Base = ptr->base;

    if (Base[S_SCOPE] == 6 || Base[S_SCOPE] == 7) { // SC_GLOBAL or SC_PREDEF
        h = Base[S_HASHVAL]; // SymTab[sym][S_HASHVAL]

        // sym = NewEntry(SymTab[sym][S_NAME], 0, 0, VARIABLE, h, buckets[h], 0)
        _2125 = Base[S_NAME]; // SymTab[sym][S_NAME]

        ptr = SEQ_PTR(_4SymTab);
        Base = ptr->base;

        _2133 = Base[h]; // buckets[h]
        Ref(_2133);
        Ref(_2125);
        Ref(_2133);
        sym = _10NewEntry(_2125, 0, 0, -100, h, _2133, 0);

        // buckets[h] = sym
        Base[h] = sym;
    }

    ptr = SEQ_PTR(_4SymTab);
    Base = ptr->base + sym;
    ptr = SEQ_PTR(*Base);
    Base = ptr->base;

    Base[S_MODE] = 2; // SymTab[sym][S_MODE] = M_CONSTANT
    Base[S_SCOPE] = 5; // SymTab[sym][S_SCOPE] = SC_LOCAL
    Base[S_TOKEN] = 523; // SymTab[sym][S_TOKEN] = NAMESPACE
    /* S_OBJ will get the file ref. */

    DeRef(_2125);
    DeRef(_2133);
    return sym;
}

int _11StringToken()
{
    int ch, gtext, m;
    int _2142, _2145;
    int _2;

    ch = _11getch();

    // ch = ' ' or ch = '\t'
    while (ch == 32 || ch == 9) {
        /* Skip whitespace */
        ch = _11getch();
    }

    // gtext = ""
    RefDS(_39);
    gtext = _39;

    // while not find(ch,  {' ', '\t', '\n', '\r', END_OF_FILE_CHAR}) do
    while (ch != 32 && ch != 9 && ch != 10 && ch != 13 && ch != 26) {
        Append(&gtext, gtext, ch);
        ch = _11getch();
    }

    _6bp--;
    m = e_match(_2152, gtext);

    if (m) {
        rhs_slice_target = (object_ptr)&gtext;
        RHS_Slice((s1_ptr)gtext, 1, m - 1);

        // if ch = ' ' or ch = '\t' then
        if (ch == 32 || ch == 9) {
            _11read_line();
        }
    }

    return gtext;
}

int _11IncludeScan()
/* Scan include name and (possible) namespace.
   For namespace, syntax should be 'include x as y'. */
{
    int ch;
    int gtext, s = 0;
    int _2159 = 0, _2162 = 0;
    int _1, _2;

    ch = _11getch();

    // ch = ' ' or ch = '\t'
    while (ch == 32 || ch == 9) {
        /* Skip whitespace */
        ch = _11getch();
    }

    RefDS(_39);
    gtext = _39;

    if (ch == 34) { // '"'
        ch = _11getch();

        // while not find(ch,  {' ', '\t', '\n', '\r', END_OF_FILE_CHAR}) do
        while (ch != 32 && ch != 9 && ch != 10 && ch != 13 && ch != 26) {
            if (ch == 92) // '\\'
                ch = _11EscapeChar(_11getch());
            Append(&gtext, gtext, ch);
            ch = _11getch();
        }

        if (ch != 34) { // '"'
            // CompileErr("missing closing quote on file name")
            RefDS(_2175);
            _6CompileErr(_2175);
        }
    }
    else {
        // while not find(ch,  {' ', '\t', '\n', '\r', END_OF_FILE_CHAR}) do
        while (ch != 32 && ch != 9 && ch != 10 && ch != 13 && ch != 26) {
            Append(&gtext, gtext, ch);
            ch = _11getch();
        }

        _6bp--;
    }

    if (SEQ_PTR(gtext)->length == 0) {
        // CompileErr("file name is missing")
        RefDS(_2182);
        _6CompileErr(_2182);
    }

    RefDS(gtext);
    DeRef(_11new_include_name);
    _11new_include_name = gtext;

    ch = _11getch();

    while (ch == 32 || ch == 9) {
        /* Skip whitespace */
        ch = _11getch();
    }

    _11new_include_space = 0;

    if (ch == 97) { // 'a'
        ch = _11getch();
        if (ch == 115) { // 's'
            ch = _11getch();
            if (ch == 32 || ch == 9) {
                ch = _11getch();
                // ch = ' ' or ch = '\t'
                while (ch == 32 || ch == 9) {
                    /* Skip whitespace */
                    ch = _11getch();
                }

                /* a-z, A-Z, and _ : Valid letter. Namespaces, like variables, must
                   begin with a letter. */
                if (ch >= 65 && ch <= 90 || ch >= 97 && ch <= 123 || ch == 95) {
                    _1 = NewS1(1);
                    _2 = (int)((s1_ptr)_1)->base;
                    *((int *)(_2+4)) = ch;
                    gtext = MAKE_SEQ(_1);

                    ch = _11getch();

                    /* 0-9, a-z, A-Z, and _ : All valid naming characters. */
                    while (ch >= 48 && ch <= 57 || ch >= 65 && ch <= 90 || ch >= 97 && ch <= 123 || ch == 95) {
                        Append(&gtext, gtext, ch);
                        ch = _11getch();
                    }

                    _6bp--;

                    RefDS(gtext);
                    s = _10keyfind(gtext, -1);

                    _2159 = SEQ_PTR(s)->base[1]; // s[T_ID]

                    // VARIABLE or FUNC or TYPE or PROC
                    if (_2159 != -100 && _2159 != 501 && _2159 != 504 && _2159 != 27) {
                        // CompileErr("a new namespace identifier is expected here")
                        RefDS(_2218);
                        _6CompileErr(_2218);
                    }

                    // new_include_space = NameSpace_declaration(s[T_SYM])
                    _2162 = SEQ_PTR(s)->base[2];
                    Ref(_2162);
                    Ref(_2162);
                    _11new_include_space = _11NameSpace_declaration(_2162);
                }
                else {
                    // CompileErr("missing namespace qualifier")
                    RefDS(_2221);
                    _6CompileErr(_2221);
                }
            }
            else {
                // CompileErr("improper syntax for include-as")
                RefDS(_2222);
                _6CompileErr(_2222);
            }
        }
        else {
            // CompileErr("improper syntax for include-as")
            RefDS(_2222);
            _6CompileErr(_2222);
        }
    }
    else {

        _6bp--;
    }

    _11start_include = 1; // TRUE

    DeRefi(gtext);
    DeRef(s);
    DeRef(_2162);
    DeRef(_2159);
}

int _11same_name(int a, int b)
{
    int _1731 = 0, _1738 = 0;
    int i;

    if (_4ELINUX) {
        return (compare(a, b) == 0);
    }

    if (SEQ_PTR(a)->length != SEQ_PTR(b)->length) {
        return 0; // FALSE
    }

    for (i = 1;i < SEQ_PTR(a)->length + 1;i++) {
        // if upper(a[i]) != upper(b[i]) then
        DeRef(_1731);
        _1731 = SEQ_PTR(a)->base[i];
        Ref(_1731);
        Ref(_1731);
        _1731 = _3upper(_1731);
        DeRef(_1738);
        _1738 = SEQ_PTR(b)->base[i];
        Ref(_1738);
        Ref(_1738);
        _1738 = _3upper(_1738);
        if (_1731 != _1738) {
            DeRef(_1738);
            DeRef(_1731);
            return 0; // FALSE
        }
    }

    // return TRUE
    DeRef(_1738);
    DeRef(_1731);
    return 1;
}

int _11IncludePush()
{
    int i, new_file, new_name;
    int _1741 = 0, _1748;
    int _1, _2;
    object_ptr Base;
    s1_ptr ptr;

    _11start_include = 0; // FALSE

    new_file = _11path_open();
    /* Not the new file, just the number reference to it.
       This sets _11new_include_name to the path. */

    RefDS(_11new_include_name);
    new_name = _10name_ext(_11new_include_name);

    ptr = SEQ_PTR(_4file_name);

    for(i = ptr->length;i > 0;i--) {
        // same_name(new_name, name_ext[i]) and equal(dir(_11new_include_name), dir(name_ext[i]))
        if (_11same_name(new_name, _10name_ext(ptr->base[i])) &&
        !compare(_12dir(_11new_include_name), _12dir(ptr->base[i]))) {
            if (_11new_include_space) {
                // SymTab[new_include_space][S_OBJ] = i -- but note any namespace

                ptr = SEQ_PTR(_4SymTab);
                Base = ptr->base + _11new_include_space;
                ptr = SEQ_PTR(*Base);
                Base = ptr->base;
                Base[S_OBJ] = i;
            }

            EClose(new_file);

            // return -- ignore it
            DeRef(new_name);
            return 0;
        }
    }

    // IncludeStk = append(IncludeStk,
    _1 = NewS1(9);
    _2 = (int)((s1_ptr)_1)->base;
    *((int *)(_2+4)) = _4current_file_no;
    *((int *)(_2+8)) = _4line_number;
    *((int *)(_2+12)) = _11src_file;
    *((int *)(_2+16)) = _4file_start_sym;
    *((int *)(_2+20)) = _4OpWarning;
    *((int *)(_2+24)) = _4OpTrace;
    *((int *)(_2+28)) = _4OpTypeCheck;
    *((int *)(_2+32)) = _4OpProfileTime;
    *((int *)(_2+36)) = _4OpProfileStatement;
    _1748 = MAKE_SEQ(_1);
    RefDS(_1748);
    Append(&_11IncludeStk, _11IncludeStk, _1748);

    /* There used to be checks for too-deep file nesting and
       too many includes. I've removed too-deep nesting, since it
       doesn't seem to hurt anything. Too many includes would never
       be reached since we use our own internal EOpen which has a max
       of 45 files. */

    _4file_start_sym = _10last_sym;
    _11src_file = new_file;

    RefDS(_11new_include_name);
    Append(&_4file_name, _4file_name, _11new_include_name);

    // current_file_no = length(file_name)
    _4current_file_no = SEQ_PTR(_4file_name)->length;

    if (_11new_include_space != 0) {
        // SymTab[new_include_space][S_OBJ] = current_file_no
        ptr = SEQ_PTR(_4SymTab);
        Base = ptr->base + _11new_include_space;
        ptr = SEQ_PTR(*Base);
        Base = ptr->base; // S_OBJ
        Base[S_OBJ] = _4current_file_no;
    }

    _4line_number = 0;

    DeRef(new_name);
    DeRef(_1748);
    DeRef(_1741);
    return 0;
}

int _11IncludePop()
/* Remove our last include file's IncludeStk info.
   If this file is our last, return 0 to stop scanning. */
{
    int len, top;
    object_ptr Base;
    s1_ptr ptr;

    _10HideLocals();
    EClose(_11src_file);

    ptr = SEQ_PTR(_11IncludeStk);
    /* ptr is set early to set len easier. */
    len = ptr->length;

    if (len == 0)
        /* End of last file. Stop scanning. */
        return 0;

    Base = ptr->base + ptr->length;
    ptr = SEQ_PTR(*Base);
    Base = ptr->base;

    _4current_file_no = Base[1];    // top[FILE_NO]
    _4line_number = Base[2];        // top[LINE_NO]
    _11src_file = Base[3];          // top[FILE_PTR]
    _4file_start_sym = Base[4];     // top[FILE_START_SYM]
    _4OpWarning = Base[5];          // top[OP_WARNING]
    _4OpTrace = Base[6];            // top[OP_TRACE]
    _4OpTypeCheck = Base[7];        // top[OP_TYPE_CHECK]
    _4OpProfileTime = Base[8];      // top[OP_PROFILE_TIME]
    _4OpProfileStatement = Base[9]; // top[OP_PROFILE_STATEMENT]

    rhs_slice_target = (object_ptr)&_11IncludeStk;
    RHS_Slice((s1_ptr)_11IncludeStk, 1, len - 1);

    return 1;
}

int _11MakeInt(int text)
{
    int i, len, num;
    int _1788 = 0, _1789 = 0;
    int _1783;
    int _1, _2;
    object_ptr Base;
    s1_ptr ptr;

    ptr = SEQ_PTR(text);
    Base = ptr->base;

    len = ptr->length;

    /* More than 9 digits will overflow. */
    if (len > 9) {
        // return -1 -- use f.p. calculations
        DeRefDSi(text);
        return -1;
    }

    /* Initial value for num */
    num = Base[1] - 48;

    /* Add up the rest of the number.
       A bit odd looking, I think, but it works.
       Ex : 58209
       5, 58, 582, 5820, 58209. */
    for (i = 2;i < len+1;i++) {
        num = num * 10 + (Base[i] - 48);
    }

    // return num
    DeRefDSi(text);
    DeRef(_1788);
    DeRef(_1789);
    return num;
}

int _11EscapeChar(int c)
{
    switch (c) {
        case 110: // \n
            return 10;
            break;
        case 116: // \t
            return 9;
            break;
        case 92: // \\
            return 92;
            break;
        case 114: // \r
            return 13;
            break;
        case 34: // \"
            return 34;
            break;
        case 39: // \'
            return c;
            break;
        case 47: // \/
            /* Just grab _4SLASH. We set it to this in main.c */
            return _4SLASH;
        default:
            // "unknown escape character"
            err_add(NewString("unknown escape character"));
            set_err_stack();
            break;
    }
}

int _11my_sscanf(int yytext)
{
    int c, dec = 0, e_mag, e_sign, i;
    int mantissa, ndigits;
    int _2, _1799, _1807 = 0;

    if (SEQ_PTR(yytext)->length < 2) {
        // CompileErr("number not formed correctly")
        RefDS(_1801);
        _6CompileErr(_1801);
    }

    // mantissa = 0.0
    RefDS(_1802);
    mantissa = _1802;
    ndigits = 0;

    Append(&yytext, yytext, 0); /* Add end marker. */

    // c = yytext[1]
    _2 = (int)SEQ_PTR(yytext);
    c = (int)*(((s1_ptr)_2)->base + 1);

    i = 2;

    while (c >= 48 && c <= 57) { // '0' to '9'
        /* Overflow highly likely. Use doubles all the way. */
        ndigits++;

        // mantissa = mantissa * 10.0 + (c - '0')
        DeRef(_1807);
        _1807 = NewDouble(DBL_PTR(mantissa)->dbl * DBL_PTR(_1809)->dbl);
        DeRef(_1799);
        _1799 = NewDouble((double)(c - 48));
        DeRefDS(mantissa);
        mantissa = NewDouble(DBL_PTR(_1807)->dbl + DBL_PTR(_1799)->dbl);

        // c = yytext[i]
        _2 = (int)SEQ_PTR(yytext);
        c = (int)*(((s1_ptr)_2)->base + i);
        i++;
    }


    // if c = '.' then
    if (c == 46) {
        // c = yytext[i]
        _2 = (int)SEQ_PTR(yytext);
        c = (int)*(((s1_ptr)_2)->base + i);

        i++;

        // dec = 10.0
        RefDS(_1809);
        DeRef(dec);
        dec = _1809;

        while (c >= 48 && c <= 57) { // '0' to '9'
            ndigits++;

            // mantissa = mantissa + (c - '0') / dec
            DeRef(_1807);
            _1807 = NewDouble((double)(c - 48) / DBL_PTR(dec)->dbl);
            mantissa = NewDouble(DBL_PTR(mantissa)->dbl + DBL_PTR(_1807)->dbl);

            dec = NewDouble(DBL_PTR(dec)->dbl * DBL_PTR(_1809)->dbl);
            /* Multiply dec by 10 so each new digit comes in to the next spot.
               First .x, then .0x, then .00x, etc. */
            _2 = (int)SEQ_PTR(yytext);
            c = (int)*(((s1_ptr)_2)->base + i);

            i++;
        }
    }

    /* Should have a number by now. If not, bad formation. */
    if (ndigits == 0) {
        // return {}  -- no digits
        RefDS(_39);
        DeRefDSi(yytext);
        DeRef(mantissa);
        DeRef(dec);
        DeRef(_1799);
        DeRef(_1807);
        return _39;
    }

    if (c == 101 || c == 69) { // 'e' or 'E'
        e_sign = 1;
        e_mag = 0;

        // c = yytext[i]
        _2 = (int)SEQ_PTR(yytext);
        c = (int)*(((s1_ptr)_2)->base + i);

        i++;

        /* Find the sign */
        if (c == 45) // '-'
            e_sign = -1;
        else if (c != 43) // ! = '+'
            /* No sign. Go back. */
            i--;

        // c = yytext[i]
        _2 = (int)SEQ_PTR(yytext);
        c = (int)*(((s1_ptr)_2)->base + i);

        i++;

        if (c >= 48 && c <= 57) { // '0' to '9'
            e_mag = c - 48; // 48 offsets '0' to '9'

            // c = yytext[i]
            _2 = (int)SEQ_PTR(yytext);
            c = (int)*(((s1_ptr)_2)->base + i);

            i++;

            while (c >= 48 && c <= 57) { // '0' to '9'
                // e_mag = e_mag * 10 + c - '0'
                DeRef(_1799);
                if (e_mag == (short)e_mag)
                    _1799 = e_mag * 10;
                else
                    _1799 = NewDouble(e_mag * (double)10);
                if (IS_ATOM_INT(_1799)) {
                    _1799 = _1799 + c;
                    if (_1799 + HIGH_BITS >= 0)
                        _1799 = NewDouble((double)_1799);
                }
                else {
                    _1799 = NewDouble(DBL_PTR(_1799)->dbl + (double)c);
                }
                if (IS_ATOM_INT(_1799)) {
                    e_mag = _1799 - 48;
                }
                else {
                    e_mag = NewDouble(DBL_PTR(_1799)->dbl - (double)48);
                }

                _2 = (int)SEQ_PTR(yytext);
                c = (int)*(((s1_ptr)_2)->base + i);

                i++;

                // if e_mag > 1000 then -- avoid int overflow. can only have
                if (e_mag > 1000)
                    break; // exit
            }
        }
        else {
            /* No exponent. Send back a bad number. */
            RefDS(_39);
            DeRefDSi(yytext);
            DeRef(mantissa);
            DeRef(dec);
            DeRef(_1799);
            DeRef(_1807);
            return _39;
        }

        e_mag = e_mag * e_sign;

        if (e_mag > 308) {
            // mantissa = mantissa * power(10.0, 308.0)
            DeRef(_1799);
            _1799 = Dpower(DBL_PTR(_1809), DBL_PTR(_1858));
            mantissa = NewDouble(DBL_PTR(mantissa)->dbl * DBL_PTR(_1799)->dbl);
            e_mag = e_mag - 308;

            while (e_mag > 0) {
                // mantissa = mantissa * 10.0 -- Could crash? No we'll get INF.
                mantissa = NewDouble(DBL_PTR(mantissa)->dbl * DBL_PTR(_1809)->dbl);

                e_mag--;
            }
        }
        else {
            // mantissa = mantissa * power(10.0, e_mag)
            DeRef(_1799);
            temp_d.dbl = (double)e_mag;
            _1799 = Dpower(DBL_PTR(_1809), &temp_d);
            mantissa = NewDouble(DBL_PTR(mantissa)->dbl * DBL_PTR(_1799)->dbl);
        }
    }

    // return mantissa
    DeRefDSi(yytext);
    DeRef(dec);
    DeRef(_1799);
    DeRef(_1807);
    return mantissa;
}

int _11Scanner()
{
    int class, ch, i, is_int, sp;
    int yytext = 0;
    int d = 0;
    int tok = 0;
    int name = 0;
    int _1867 = 0;
    int _1871 = 0;
    int _1, _2;
L1:
    while (1) {
        // ch = ThisLine[bp]  -- getch inlined (in all the "hot" spots)
        _2 = (int)SEQ_PTR(_6ThisLine);
        ch = (int)*(((s1_ptr)_2)->base + _6bp);

        _6bp++;

        // while ch = ' ' or ch = '\t' do
        while (ch == 32 || ch == 9) {
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);
            _6bp++;
        }

        // class = char_class[ch]
        _2 = (int)SEQ_PTR(_11char_class);
        class = (int)*(((s1_ptr)_2)->base + ch);

        // if class = LETTER then
        if (class == -2) {
            sp = _6bp;

            // ch = ThisLine[bp]  -- getch
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            _6bp++;

            while (1) {
                DeRef(_1871);
                _2 = (int)SEQ_PTR(_11id_char);
                _1871 = (int)*(((s1_ptr)_2)->base + ch);
                if (_1871 == 0)
                    break;

                // ch = ThisLine[bp] -- getch
                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);

                _6bp++;
            }

            // yytext = ThisLine[sp-1..bp-2]
            rhs_slice_target = (object_ptr)&yytext;
            RHS_Slice((s1_ptr)_6ThisLine, sp - 1, _6bp - 2);

            _6bp--;

            // tok = keyfind(yytext, -1)
            RefDS(yytext);
            tok = _10keyfind(yytext, -1);

            // if tok[T_ID] = NAMESPACE then
            _2 = (int)SEQ_PTR(tok);
            _1867 = (int)*(((s1_ptr)_2)->base + 1);
            Ref(_1867);
            if (_1867 == 523) {
                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);
                _6bp++;

                // while ch = ' ' or ch = '\t' do
                while (ch == 32 || ch == 9) {
                    _2 = (int)SEQ_PTR(_6ThisLine);
                    ch = (int)*(((s1_ptr)_2)->base + _6bp);
                    _6bp++;
                }

                // if ch = ':' then
                if (ch == 58) {
                    /* Namespace. Figure out where it goes. */
                    _2 = (int)SEQ_PTR(_6ThisLine);
                    ch = (int)*(((s1_ptr)_2)->base + _6bp);
                    _6bp++;

                    while (ch == 32 || ch == 9) { // ' ' or '\t'
                        _2 = (int)SEQ_PTR(_6ThisLine);
                        ch = (int)*(((s1_ptr)_2)->base + _6bp);
                        _6bp++;
                    }

                    RefDS(_39);
                    DeRefi(yytext);
                    yytext = _39;

                    // while id_char[ch] do
                    while (1) {
                        DeRef(_1867);
                        _2 = (int)SEQ_PTR(_11id_char);
                        _1867 = (int)*(((s1_ptr)_2)->base + ch);
                        if (!_1867)
                            break;

                        Append(&yytext, yytext, ch);
                        ch = _11getch();
                    }

                    _6bp--;

                    // if length(yytext) = 0 then
                    DeRef(_1867);
                    _1867 = SEQ_PTR(yytext)->length;
                    if (SEQ_PTR(yytext)->length == 0) {
                        // CompileErr("an identifier is expected here")
                        RefDS(_1907);
                        _6CompileErr(_1907);
                    }

                    // tok = keyfind(yytext, SymTab[tok[T_SYM]][S_OBJ])
                    DeRef(_1867);
                    _2 = (int)SEQ_PTR(tok);
                    _1867 = (int)*(((s1_ptr)_2)->base + 2);
                    Ref(_1867);
                    _2 = (int)SEQ_PTR(_4SymTab);
                    if (!IS_ATOM_INT(_1867))
                        _1867 = (int)*(((s1_ptr)_2)->base + (int)(DBL_PTR(_1867)->dbl));
                    else
                        _1867 = (int)*(((s1_ptr)_2)->base + _1867);
                    RefDS(_1867);
                    _2 = (int)SEQ_PTR(_1867);
                    _1867 = (int)*(((s1_ptr)_2)->base + 1);
                    Ref(_1867);
                    RefDS(yytext);
                    Ref(_1867);
                    tok = _10keyfind(yytext, _1867);
                }
                else
                    _6bp--;
            }

            // return tok
            DeRefi(yytext);
            DeRef(d);
            DeRef(name);
            DeRef(_1867);
            DeRef(_1871);
            return tok;
        }

        // elsif class <= ILLEGAL_CHAR or class = EQUALS then
        if (class <= -20 || class == 3 ) {
            // return {class, 0} -- brackets, punctuation, eof, illegal char etc.
            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;
            ((int *)_2)[1] = class;
            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == -6) { // NEWLINE
            if (_11start_include) {
                _11IncludePush();
            }
            _11read_line();
            continue;
        }

        if (class == -3 || class == -7) { // DOT or DIGIT
            if (class == -3) { // DOT
                if (_11getch() == 46) { // '.'
                    // return {SLICE, 0}
                    _1 = NewS1(2);
                    _2 = (int)((s1_ptr)_1)->base;
                    ((int *)_2)[1] = 516;
                    ((int *)_2)[2] = 0;
                    _1871 = MAKE_SEQ(_1);
                    DeRefi(yytext);
                    DeRef(d);
                    DeRef(tok);
                    DeRef(name);
                    DeRef(_1867);
                    return _1871;
                }
                else
                    _6bp--;
            }

            // yytext = {ch}
            _1 = NewS1(1);
            _2 = (int)((s1_ptr)_1)->base;
            *((int *)(_2+4)) = ch;
            yytext = MAKE_SEQ(_1);

            if (ch == 46) // '.'
                is_int = 0; // FALSE
            else
                is_int = 1; // TRUE

            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);
            _6bp++;

            /* Number scan. Add 0-9 to yytext. */
            while (ch >= 48 && ch <= 57) {
                Append(&yytext, yytext, ch);
                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);
                _6bp++;
            }

            if (ch == 46) { // '.'
                ch = _11getch();

                if (ch == 46) { // '.'
                    /* ungetch to return slice?
                       Can we even get a slice here? */
                    _6bp--;
                }
                else {
                    is_int = 0; // FALSE

                    // if yytext[1] = '.' then
                    DeRef(_1871);
                    _2 = (int)SEQ_PTR(yytext);
                    _1871 = (int)*(((s1_ptr)_2)->base + 1);
                    if (_1871 == 46) {
                        // CompileErr("only one decimal point allowed")
                        RefDS(_1948);
                        _6CompileErr(_1948);
                    }
                    else
                        Append(&yytext, yytext, 46); // 46 = '.'

                    if (ch >= 48 && ch <= 57) {
                        /* Number scan. Add 0-9 to yytext. */
                        while (ch >= 48 && ch <= 57) {
                            Append(&yytext, yytext, ch);
                            _2 = (int)SEQ_PTR(_6ThisLine);
                            ch = (int)*(((s1_ptr)_2)->base + _6bp);
                            _6bp++;
                        }
                    }
                    else {
                        // CompileErr("fractional part of number is missing")
                        RefDS(_1958);
                        _6CompileErr(_1958);
                    }
                }
            }

            if (ch == 101 || ch == 69) { // 'e' or 'E'
                is_int = 0; // FALSE
                Append(&yytext, yytext, ch);
                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);
                _6bp++;

                if (ch == 45 || ch == 43 || ch >= 48 && ch <= 57) { // '-' or '+' or 0-9
                    Append(&yytext, yytext, ch);
                }
                else {
                    // CompileErr("exponent not formed correctly")
                    RefDS(_1971);
                    _6CompileErr(_1971);
                }

                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);
                _6bp++;

                /* Number scan. Add 0-9 to yytext. */
                while (ch >= 48 && ch <= 57) {
                    Append(&yytext, yytext, ch);
                    _2 = (int)SEQ_PTR(_6ThisLine);
                    ch = (int)*(((s1_ptr)_2)->base + _6bp);
                    _6bp++;
                }
            }

            _6bp--;

            // i = MakeInt(yytext)
            RefDS(yytext);
            i = _11MakeInt(yytext);

            if (is_int && i != -1) {
                // return {ATOM, NewIntSym(i)}
                _1871 = _10NewIntSym(i);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1871;
                _1871 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1867);
                return _1871;
            }

            // d = my_sscanf(yytext)
            RefDS(yytext);
            d = _11my_sscanf(yytext);

            if (IS_SEQUENCE(d)) {
                // CompileErr("number not formed correctly")
                RefDS(_1801);
                _6CompileErr(_1801);
            }

            if (is_int && d <= 1073741823) { // 107... is MAXINT_DBL
                // return {ATOM, NewIntSym(d)} -- 1 to 1.07 billion
                Ref(d);
                _1867 = _10NewIntSym(d);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1867;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
            else {
                // return {ATOM, NewDoubleSym(d)}
                Ref(d);
                _1867 = _10NewDoubleSym(d);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1867;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
        }

        if (class == 10) { // MINUS
            // ch = ThisLine[bp]
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            _6bp++;

            if (ch == 45) { // '-'
                /* Double '-' is comment. Move to the
                   next line. Include if necessary. */
                if (_11start_include)
                    _11IncludePush();
                _11read_line();
                continue;
            }

            switch (ch) {
                case 61: // '='
                    // return {MINUS_EQUALS, 0}
                    DeRef(_1867);
                    _1 = NewS1(2);
                    _2 = (int)((s1_ptr)_1)->base;
                    ((int *)_2)[1] = 519;
                    ((int *)_2)[2] = 0;
                    _1867 = MAKE_SEQ(_1);
                    DeRefi(yytext);
                    DeRef(d);
                    DeRef(tok);
                    DeRef(name);
                    DeRef(_1871);
                    return _1867;
                    break;
                default:
                    _6bp--;
                    // return {MINUS, 0}
                    DeRef(_1867);
                    _1 = NewS1(2);
                    _2 = (int)((s1_ptr)_1)->base;
                    ((int *)_2)[1] = 10;
                    ((int *)_2)[2] = 0;
                    _1867 = MAKE_SEQ(_1);
                    DeRefi(yytext);
                    DeRef(d);
                    DeRef(tok);
                    DeRef(name);
                    DeRef(_1871);
                    return _1867;
                    break;
            }
        }

        if (class == -4) { // DOUBLE_QUOTE
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            _6bp++;

            RefDS(_39);
            DeRefi(yytext);
            yytext = _39;

            while (ch != 10 && ch != 13) {
                /* I don't know how to break from
                   switch in while, so I put this alone. */
                if (ch == 34) // '"'
                    break; /* End of string. */

                    switch (ch) {
                        case 92: // '\\'
                        _1871 = _11EscapeChar(_11getch());
                        Append(&yytext, yytext, _1871);
                        break;
                    case 9: // '\t'
                        // CompileErr("tab character found in string - use \\t instead")
                        RefDS(_2011);
                        _6CompileErr(_2011);
                        break;
                    default:
                        Append(&yytext, yytext, ch);
                        break;
                }

                // ch = ThisLine[bp]  -- getch
                _2 = (int)SEQ_PTR(_6ThisLine);
                ch = (int)*(((s1_ptr)_2)->base + _6bp);

                _6bp++;
            }

            if (ch == 10 || ch == 13) {
                // CompileErr("end of line reached with no closing \"")
                RefDS(_2019);
                _6CompileErr(_2019);
            }

            // return {STRING, NewStringSym(yytext)}
            RefDS(yytext);
            _1867 = _10NewStringSym(yytext);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;
            ((int *)_2)[1] = 503;
            ((int *)_2)[2] = _1867;
            _1867 = MAKE_SEQ(_1);
            DeRefDSi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == 11) { // PLUS
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            if (ch == 61) { // '='
                // return {PLUS_EQUALS, 0}
                _6bp++;
                DeRef(_1867);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 518;
                ((int *)_2)[2] = 0;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
            else {
                // return {PLUS, 0}
                DeRef(_1867);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 11;
                ((int *)_2)[2] = 0;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
        }

        if (class == 15) { // CONCAT
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 522; // CONCAT_EQUALS
            }
            else {
                ((int *)_2)[1] = 15; // CONCAT
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == 13) { // MULTIPLY
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 520; // MULTIPLY_EQUALS
            }
            else {
                ((int *)_2)[1] = 13; // MULTIPLY
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == 14) { // DIVIDE
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 521; // DIVIDE_EQUALS
            }
            else {
                ((int *)_2)[1] = 14; // DIVIDE
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == 1) { // LESS
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 5; // LESS_EQUALS
            }
            else {
                ((int *)_2)[1] = 1; // LESS
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == 6) { // GREATER
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 2; // GREATEREQ
            }
            else {
                ((int *)_2)[1] = 6; // GREATER
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == -1) { // BANG
            _2 = (int)SEQ_PTR(_6ThisLine);
            ch = (int)*(((s1_ptr)_2)->base + _6bp);

            DeRef(_1867);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;

            if (ch == 61) { // '='
                _6bp++;
                ((int *)_2)[1] = 4; // NOTEQ
            }
            else {
                ((int *)_2)[1] = -1; // BANG
            }

            ((int *)_2)[2] = 0;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == -5) { // SINGLE_QUOTE
            ch = _11getch();

            switch (ch) {
                case 92: // '\\'
                    ch = _11EscapeChar(_11getch());
                    break;
                case 9: // '\t'
                    // CompileErr("tab character found in string - use \\t instead")
                    RefDS(_2011);
                    _6CompileErr(_2011);
                    break;
                case 39: // '\''
                    // CompileErr("single-quote character is empty")
                    RefDS(_2092);
                    _6CompileErr(_2092);
                    break;
            }

            if (_11getch() != 39) { // '\''
                // CompileErr("character constant is missing a closing '")
                RefDS(_2095);
                _6CompileErr(_2095);
            }

            // return {ATOM, NewIntSym(ch)}
            _1867 = _10NewIntSym(ch);
            _1 = NewS1(2);
            _2 = (int)((s1_ptr)_1)->base;
            ((int *)_2)[1] = 502;
            ((int *)_2)[2] = _1867;
            _1867 = MAKE_SEQ(_1);
            DeRefi(yytext);
            DeRef(d);
            DeRef(tok);
            DeRef(name);
            DeRef(_1871);
            return _1867;
        }

        if (class == -11) { // NUMBER_SIGN
            /* Hex value or shebang. */
            i = 0;
            is_int = -1;

            _1867 = 1073741823 / 32; /* MAXINT_VAL / 32 */
            /* No chance of a double, so safe to use int all the way. */
            while (i < _1867) {
                ch = _11getch();

                if (ch >= 48 && ch <= 57) { // '0' to '9'
                    i = i * 16 + ch - 48; /* 48 offsets '0' to '9' */
                    is_int = 1; // TRUE
                }
                else {
                    if (ch >= 65 && ch <= 70) { // >= 'A' && <= 'F'
                        i = (i * 16) + ch - 55; /* 55 handles offset of 'A' to 'F' */
                        is_int = 1; // TRUE
                    }
                    else
                        break;
                }
            }

            if (is_int == -1) {
                if (ch = 33) { // '!'
                    /* Linux shebang. If it's on the first line,
                       ignore it. Otherwise, give fatal error. */

                    if (_4line_number > 1) {
                        // CompileErr("#! may only be on the first line of a program")
                        RefDS(_2051);
                        _6CompileErr(_2051);
                    }

                    if (_11start_include)
                        _11IncludePush();

                    _11read_line();
                }
                else {
                    // CompileErr("hex number not formed correctly")
                    RefDS(_2052);
                    _6CompileErr(_2052);
                }
            }

            if (i >= 1073741823 / 32) { // MAXINT_VAL / 32
                DeRef(d);
                d = i; /* Start from where we left off at. */

                is_int = 0; // FALSE
                while (1) {
                    ch = _11getch();

                    if (ch >= 48 && ch <= 57) {
                        // d = (d * 16) + ch - '0'
                        if (IS_ATOM_INT(d)) {
                            if (d == (short)d)
                                _1867 = d * 16;
                            else
                                _1867 = NewDouble(d * (double)16);
                        }
                        else {
                            _1867 = NewDouble(DBL_PTR(d)->dbl * (double)16);
                        }
                        if (IS_ATOM_INT(_1867)) {
                            _1867 = _1867 + ch;
                            if (_1867 + HIGH_BITS >= 0)
                                _1867 = NewDouble((double)_1867);
                        }
                        else {
                            _1867 = NewDouble(DBL_PTR(_1867)->dbl + (double)ch);
                        }
                        DeRef(d);
                        if (IS_ATOM_INT(_1867)) {
                            d = _1867 - 48;
                            if (d + HIGH_BITS >= 0)
                                d = NewDouble((double)d);
                        }
                        else {
                            d = NewDouble(DBL_PTR(_1867)->dbl - (double)48);
                        }
                    }
                    else {
                        if (ch >= 65 && ch <= 70) {
                            // d = (d * 16) + ch - ('A'- 10)
                            DeRef(_1871);
                            if (IS_ATOM_INT(d)) {
                                if (d == (short)d)
                                    _1871 = d * 16;
                                else
                                    _1871 = NewDouble(d * (double)16);
                            }
                            else {
                                _1871 = NewDouble(DBL_PTR(d)->dbl * (double)16);
                            }
                            if (IS_ATOM_INT(_1871)) {
                                _1871 = _1871 + ch;
                                if (_1871 + HIGH_BITS >= 0)
                                _1871 = NewDouble((double)_1871);
                            }
                            else {
                                _1871 = NewDouble(DBL_PTR(_1871)->dbl + (double)ch);
                            }
                            DeRef(d);
                            if (IS_ATOM_INT(_1871)) {
                                d = _1871 - 55;
                                if (d + HIGH_BITS >= 0)
                                    d = NewDouble((double)d);
                            }
                            else {
                                d = NewDouble(DBL_PTR(_1871)->dbl - (double)55);
                            }
                        }
                        else
                            break;
                    }
                }
            }

            _6bp--;

            if (is_int) {
                // return {ATOM, NewIntSym(i)}
                _1867 = _10NewIntSym(i);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1867;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }

            if (d <= 1073741823) { // <= MAXINT_DBL
                // return {ATOM, NewIntSym(d)}
                Ref(d);
                _1867 = _10NewIntSym(d);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1867;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
            else {
                // return {ATOM, NewDoubleSym(d)}
                Ref(d);
                _1867 = _10NewDoubleSym(d);
                _1 = NewS1(2);
                _2 = (int)((s1_ptr)_1)->base;
                ((int *)_2)[1] = 502;
                ((int *)_2)[2] = _1867;
                _1867 = MAKE_SEQ(_1);
                DeRefi(yytext);
                DeRef(d);
                DeRef(tok);
                DeRef(name);
                DeRef(_1871);
                return _1867;
            }
        }

        // InternalErr("Scanner()")
        RefDS(_2124);
        _6InternalErr(_2124);
    }
}

